<?php

class APP_Controllers_Articles {

    public function index() {
        $view = new Core_Library_View_View('registration', 'index');
        $validator = new Core_Library_Validator();
        $user = new App_Models_Registration();
        if (isset($_POST['registration'])
                && isset($_POST['login'])
                && isset($_POST['email'])
                && isset($_POST['password'])
                && isset($_POST['repassword'])) {
            echo '=)s';

            if ($validator->password($_POST['password'], $_POST['password'])) {
                if ($validator->email($_POST['email'])) {
                    $user->insert('users', array('login', 'email', 'password'), array($validator->escapeString($_POST['login']),
                        $validator->escapeString($_POST['email']), md5($validator->escapeString($_POST['password']))));
                } else {
                    echo "Мыло введено не корректно)";
                }
            } else {
                echo "Пароли не совпадают)";
            }
        }
        if (isset($_POST['enter'])
                && isset($_POST['login'])
                && isset($_POST['password'])) {
            if ($user->recordIsset('password', 'users', 'login', $_POST['login'])) {
                $userDataArray = $user->getData('password', 'users', 'login', $_POST['login']);
                if ($validator->password($_POST['password'], $userDataArray['password'], 'true')) {
                    $_SESSION['login'] = ($_POST['login']);
                    header("Location: http://localhost/thtp.ru/user/" . $_POST['login']);
                } else {
                    echo 'spme';
                }
            } else {
                echo 'record iiset';
            }
        }
    }

}